﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Wild2.Controllers
{
    public class FavoritesController : Controller
    {
        //
        // GET: /Favorites/

        public ActionResult Index()
        {
            Wild2.Models.Pages.Favorites.Index page = new Models.Pages.Favorites.Index();
            Int32? UserID = Wild2.Models.Auth.AuthOnSite.GetUserId();
            if (!UserID.HasValue) return RedirectToAction("Index", "Login");
            page.Favorites = Wild2.Models.Favorites.Favorites.GetFavorites(UserID.Value);
            return View(page);
        }

        public ActionResult Add()
        {
            Int32? UserID = Wild2.Models.Auth.AuthOnSite.GetUserId();
            if (!UserID.HasValue) return RedirectToAction("Index", "Login");
            Object url = HttpContext.Session[Models.Constants.SessionConstants.FAVORITES];
            if (url != null)
            {
                Models.Favorites.Favorites.AddFavorite(UserID.Value, url.ToString().Split(new char[] { '|' })[0], url.ToString().Split(new char[] { '|' })[1]);
            }
            return RedirectToAction("Index");
        }

        public ActionResult Delete(int id)
        {
            Int32? UserID = Wild2.Models.Auth.AuthOnSite.GetUserId();
            if (!UserID.HasValue) return RedirectToAction("Index", "Login");
            Models.Favorites.Favorites.DeleteFavorite(UserID.Value, id);
            return RedirectToAction("Index");
        }
    }
}
